<!DOCTYPE html>
<html lang="zh">
<head>
	<th:block th:include="include :: header('文件上传')" />
	<th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group col-sm-6">
                    <div>
                        <label class="font-noraml">租赁合同</label>
                        <div class="file-loading">
                            <input id="singleFile1" name="file" type="file">
                        </div>
                    </div>
                    <div style="height: 30px">
                    </div>
                    <div>
                        <label class="font-noraml">租赁安全协议</label>
                        <div class="file-loading">
                            <input id="singleFile2" name="file" type="file">
                        </div>
                    </div>
                </div>

                <div class="form-group col-sm-6">
                    <div>
                        <label class="font-noraml">证件照片</label>
                        <div class="file-loading">
                            <input id="singleFile3" name="file" type="file">
                        </div>
                    </div>
                    <div style="height: 30px">
                    </div>
                    <div>
                        <label class="font-noraml">管委会入住通知</label>
                        <div class="file-loading">
                            <input id="singleFile4" name="file" type="file">
                        </div>
                    </div>

                </div>
            </div>
            
            <div class="col-sm-12 select-table ">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:attachment:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:attachment:remove')}]];
        var acctchDatas = [[${@dict.getType('lease_acctch_type')}]];
        var prefix = ctx + "system/attachment";

        $(function() {
            var options = {
                url: prefix + "/list",
                removeUrl: prefix + "/remove",
                updateUrl: prefix + "/edit/{id}",
                queryParams: queryParams,
                modalName: "附件信息",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'name',
                    title: '原始文件名'
                },
                {
                    field: 'type',
                    title: '附件类型',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(acctchDatas, value);
                    }
                },
                {
                    field: 'size',
                    title: '文件大小'
                },
                {
                    field: 'ext',
                    title: '文件后缀'
                },
                {
                    field: 'url',
                    title: '访问文件的路径',
                    formatter: function(value, row, index) {
                        return "<a target='_blank' href='"+value+"'>下载</a>";
                    },
                    visible: false
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    field: 'createUserId',
                    title: '创建者ID',
                    visible: false
                },
                {
                    field: 'updateUserId',
                    title: '最后更新者ID',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="edit(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
            // 多图上传
            $("#multipleFile").fileinput({
                uploadUrl: ctx + 'system/common/uploadsSyncData',
                uploadAsync: false,
                uploadExtraData:{parentId:[[${parentId}]]}
            }).on('filebatchuploadsuccess', function (event, data, previewId, index) {
                var rsp = data.response;
                $.table.refresh();
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })

            // 单图上传
            $("#singleFile1").fileinput({
                uploadUrl: ctx + 'system/common/upload',
                maxFileCount: 1,
                autoReplace: true,
                uploadExtraData:{parentId:[[${parentId}]],type:1}
            }).on('fileuploaded', function (event, data, previewId, index) {
                var rsp = data.response;
                log.info("return url：" + rsp.url)
                log.info("reutrn fileName：" + rsp.fileName)
                log.info("reutrn newFileName：" + rsp.newFileName)
                log.info("return originalFilename：" + rsp.originalFilename)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })

            // 单图上传
            $("#singleFile2").fileinput({
                uploadUrl: ctx + 'system/common/upload',
                maxFileCount: 1,
                autoReplace: true,
                uploadExtraData:{parentId:[[${parentId}]],type:2}
            }).on('fileuploaded', function (event, data, previewId, index) {
                var rsp = data.response;
                log.info("return url：" + rsp.url)
                log.info("reutrn fileName：" + rsp.fileName)
                log.info("reutrn newFileName：" + rsp.newFileName)
                log.info("return originalFilename：" + rsp.originalFilename)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })

            // 单图上传
            $("#singleFile3").fileinput({
                uploadUrl: ctx + 'system/common/upload',
                maxFileCount: 1,
                autoReplace: true,
                uploadExtraData:{parentId:[[${parentId}]],type:3}
            }).on('fileuploaded', function (event, data, previewId, index) {
                var rsp = data.response;
                log.info("return url：" + rsp.url)
                log.info("reutrn fileName：" + rsp.fileName)
                log.info("reutrn newFileName：" + rsp.newFileName)
                log.info("return originalFilename：" + rsp.originalFilename)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })

            // 单图上传
            $("#singleFile4").fileinput({
                uploadUrl: ctx + 'system/common/upload',
                maxFileCount: 1,
                autoReplace: true,
                uploadExtraData:{parentId:[[${parentId}]],type:4}
            }).on('fileuploaded', function (event, data, previewId, index) {
                var rsp = data.response;
                log.info("return url：" + rsp.url)
                log.info("reutrn fileName：" + rsp.fileName)
                log.info("reutrn newFileName：" + rsp.newFileName)
                log.info("return originalFilename：" + rsp.originalFilename)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
        });

        function queryParams(params) {
            var search = $.table.queryParams(params);
            search.parentId = [[${parentId}]];
            return search;
        }

        function edit(id){
            $.operate.save(prefix + "/edit/"+id);
        }

        function submitHandler() {
            $.modal.close();
        }
    </script>
</body>
</html>
